金魚都能懂的網頁切版:20
https://codepen.io/mikeyam/pen/jOrOMEr?editors=1100
HTML部分使用ul和li做結構
<ul>
<li class="box1">text1</li>
<li class="box2">text2</li>
<li class="box3">text3</li>
<li class="box4">text4</li>
<li class="box5">text5</li>
<li class="box6">text6</li>
<li class="box7">text7</li>
<li class="box8">text8</li>
<li class="box9">text9</li>
</ul>
外層用flex排版,li排列出正方形,並用outline做提醒
ul{
width: 1200px;
margin: auto;
padding: 100px 0;
display: flex;
flex-wrap: wrap;
}
li{
width: 200px;
height: 200px;
text-align: center;
line-height: 200px;
/* outline: 1px solid brown; */
margin: 0 60px -40px;
position: relative;
font-size: 30px;
}
用偽元素並用transform旋轉45度
li::before{
content: '';
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: -1;
/* outline: 1px solid #00f; */
transform: rotate(45deg);
}
四跟七做位移並搭配chrome瀏覽器檢查,來調整最適當距離
li:nth-child(n+4){
left: 160px;
}
li:nth-child(n+7){
left: 0;
}
li:hover{
color: #fff;
}
li:hover::before{
background-color: #000;
}
.box1::before{background-color: #3ed0cd;}
.box2::before{background-color: #b2e086;}
.box3::before{background-color: #ef8899;}
.box4::before{background-color: #fc7b51;}
.box5::before{background-color: #2fccf9;}
.box6::before{background-color: #5f539b;}
.box7::before{background-color: #ffa55e;}
.box8::before{background-color: #fce920;}
.box9::before{background-color: #7cc85c;}